package com.yuandian.business.monitor.controller;

import com.yuandian.api.business_monitor.po.QueryConditionParams;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.business.monitor.service.IBusinessComparativeAnalysisService;
import com.yuandian.utils.StringUtils;
import com.yuandian.utils.YDateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 说明：业务对比分析controller(迁自2.5)
 *
 * @Author LinShiHe
 * @Date 2021-06-02
 */
@RestController
@Api(value = "业务对比分析接口", tags = "业务对比分析接口")
@RequestMapping("/business/overview")
public class BusinessComparativeAnalysisController {

    @Autowired
    private IBusinessComparativeAnalysisService businessComparativeAnalysisService;


    /**
     * 性能指标概况
     * @param condition 性能指标概况查询参数
     * @return 通用返回对象
     */
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemCode",  			value = "系统编码",  			paramType = "query", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "endTime", 			value = "结束时间", 			paramType = "query", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "startTime", 			value = "开始时间", 			paramType = "query", 	required = true, 	dataType = "String"),
	})
	@ApiOperation(value = "性能指标概况查询参数", notes = "性能指标概况查询参数")
    @PostMapping("/queryPerformanceIndexSurvey")
    public R<Object> queryPerformanceIndexSurvey(@RequestBody QueryConditionParams condition) {

        if (StringUtils.isNotEmpty(condition.getStartTime()) && StringUtils.isNotEmpty(condition.getEndTime())) {
            if(YDateUtil.checkTime(condition.getStartTime(), condition.getEndTime())) {
                return R.failed(1001, "暂不支持跨天!");
            }
        }

        if (StringUtils.isNotEmpty(condition.getStartTimes()) && StringUtils.isNotEmpty(condition.getEndTimes())) {
            if(YDateUtil.checkTime(condition.getStartTimes(), condition.getEndTimes())) {
                return R.failed(1001, "暂不支持跨天!");
            }
        }

        if (StringUtils.isNotEmpty(condition.getStartTimess()) && StringUtils.isNotEmpty(condition.getEndTimess())) {
            if(YDateUtil.checkTime(condition.getStartTimess(), condition.getEndTimess())) {
                return R.failed(1001, "暂不支持跨天!");
            }
        }

        if(condition.getSystemCode() == null ||  condition.getStartTime() == null || condition.getStartTime() == null) {
            return R.failed(-1, "请选择相关查询条件");
        }

        return businessComparativeAnalysisService.getPropertyIndex(condition);
    }

    /**
     * 查询业务对比分析图表数据
     * busi_detail_stat_m-DetailMinuteStatTask-详单表分钟统计-BusiDetailAreaStatHandler-延迟3分钟-api/modules/business/overview/getContrastiveCharts
     * busi_detail_stat_h-DetailHourStatTask-业务小时统计-无延迟-api/modules/business/overview/getContrastiveCharts
     * @param condition
     * @return
     */
	@ApiOperation(value = "查询业务对比分析图表数据", notes = "查询业务对比分析图表数据")
    @PostMapping("getContrastiveCharts")@ApiImplicitParams({
			@ApiImplicitParam(name = "systemCode",  			value = "系统编码",  			paramType = "query", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "endTime", 			value = "结束时间", 			paramType = "query", 	required = true, 	dataType = "String"),
			@ApiImplicitParam(name = "startTime", 			value = "开始时间", 			paramType = "query", 	required = true, 	dataType = "String"),
	})

    public R<Object> getContrastiveCharts(@RequestBody QueryConditionParams condition) {
        if (StringUtils.isNotEmpty(condition.getStartTime()) && StringUtils.isNotEmpty(condition.getEndTime())) {
            if(YDateUtil.checkTime(condition.getStartTime(), condition.getEndTime())) {
                return R.failed(1001, "暂不支持跨天!");
            }
        }

        if (StringUtils.isNotEmpty(condition.getStartTimes()) && StringUtils.isNotEmpty(condition.getEndTimes())) {
            if(YDateUtil.checkTime(condition.getStartTimes(), condition.getEndTimes())) {
                return R.failed(1001, "暂不支持跨天!");
            }
        }

        if (StringUtils.isNotEmpty(condition.getStartTimess()) && StringUtils.isNotEmpty(condition.getEndTimess())) {
            if(YDateUtil.checkTime(condition.getStartTimess(), condition.getEndTimess())) {
                return R.failed(1001, "暂不支持跨天!");
            }
        }

        if(condition.getSystemCode() == null || condition.getStartTime() == null || condition.getStartTime() == null) {
            return R.failed(-1, "请选择相关查询条件");
        }

        return businessComparativeAnalysisService.getContrastiveCharts(condition);
    }
}
